home *** CD-ROM | disk | FTP | other *** search
/ PC Format Collection 21 / PC Format CD-ROM Collection 21 (1995-12)(Future Publishing)(GB)[issue 51].iso / resource / ico.h < prev    next >
Text File  |  1991-09-20  |  4KB  |  90 lines

  1.  
  2. /***************************************************************************
  3.  * Ico.h - Description of MicroSoft Windows .ICO file format: 
  4.  *
  5.  * Alas I can't find any documentation at the moment, so the following
  6.  * is reverse engineered from looking at a couple of sample .ico files.
  7.  *
  8.  * Here is an overview of the file structure:
  9.  *
  10.  *    Ico_file_header    ........................ 6 bytes
  11.  *        Ico_file_dir   ........................16 bytes
  12.  *        Ico_file_dir
  13.  *            ...
  14.  *        ico_head       ........................28 bytes
  15.  *            color-map
  16.  *                b g r reserved..................4 bytes
  17.  *                b g r reserved
  18.  *            pixel-data
  19.  *            mask-data
  20.  *        ico_head
  21.  *            color-map
  22.  *            pixel-data
  23.  *            mask-data
  24.  *            ...
  25.  *
  26.  * A .ICO file can contain several images.  The file starts out with a
  27.  * six byte header that says how many icons are in the file.  This is
  28.  * followed by a "directory" entry of 16 bytes for each icon.  The directory
  29.  * entry among other things includes the offset of the icon proper.
  30.  *
  31.  * An Icon starts with a header.  This may be variable size because the
  32.  * size of the header (or is it the offset to the color map?) is the
  33.  * first word of the icon header.  The icon header among other things
  34.  * says how many colors are in the icon.  I've seen this be either 2, 8,
  35.  * or 16 - though I'm sure on some systems it can be 32.  The curious
  36.  * thing is that 8 color pixels still seem to be allocated 4 bits of
  37.  * data in the image bits proper.  There is a field I'm pretty sure
  38.  * says how many bits are used per pixel in storage.
  39.  *
  40.  * Anyway following the image header is the color-map in RGB? format.
  41.  * The 4th byte seems to be zero.  The number of color map entries
  42.  * seems to be related to the storage bits per pixel rather than the
  43.  * number of colors.
  44.  *
  45.  * After the color map is the color image which seems to
  46.  * be stored in packed pixel format (ie 2 pixels to the byte in 16 & 8 color
  47.  * modes,  1 per byte in 256 color mode, 8 per byte in 2 color.
  48.  * Finally there's a transparency mask for the image.  It is one
  49.  * bit per pixel.  
  50.  ***************************************************************************/
  51.  
  52. typedef struct ico_file_head
  53.     {
  54.     short u0_0;    /* Unknown, contents 0? */
  55.     short u2_1;  /* Unknown, contents 1? */
  56.     short image_count;    /* # of Icons in this file */
  57.     } Ico_file_head;
  58.  
  59. typedef struct ico_file_dir    /* One of these for each icon in file */
  60.     {
  61.     char  width;          /* Pixel width - usually 32 */
  62.     char height;          /* Pixel height - 16 or 32  */
  63.     short num_colors;    /* Number of colors - 2, 8, 16, 256? */
  64.     short u4_0;            /* Unknown, contents 0? */
  65.     short u6_0;            /* Unknown, contents 0? */
  66.     long icon_size;        /* Size of icon image */
  67.     long icon_offset;    /* Individual icon start position in file */
  68.     } Ico_file_dir;
  69.  
  70. typedef struct ico_head
  71. /* This structure looks much like a BITMAPINFOHEADER in
  72.  * windows.h, except the Height field isn't accurate. */
  73.  
  74.     {
  75.     long  head_size;    /* Header size? Always 0x28 though */
  76.     long  width;        /* Accurate?  Always 0x20? */
  77.     long  height;        /* Accurate?  0x20 when it *is* 0x10! */
  78.     short planes;        /* Number of planes of image - usually 1. */
  79.     short bits_per_pixel;    /* Number of bits/pixel in each plane. */
  80.     long  compression;    /* 0 for uncompressed. 1 & 2 are run-length. */
  81.     long image_size;    /* Size if image - mask and pixels together? */
  82.     short reserved[8];        /* Unknown - 0's? */
  83.     } Ico_head;
  84.  
  85. typedef struct ico_rgb
  86.     {
  87.     unsigned char b,g,r,reserved;    /* Values from 0 to 255 */
  88.     } Ico_rgb;
  89.  
  90.